package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.aspect.Log;
import cn.tedu.ivos.base.response.JsonResult;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/application")
@Slf4j
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    //新增
    @PostMapping("/save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam){
        log.debug("新增申请：{}",applicationSaveParam);
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }
    //查询
    @GetMapping("/select")
//    @Log
    public JsonResult selectApplication(ApplicationQuery applicationQuery){
        List<ApplicationVO> applicationVOS = applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(applicationVOS);
    }
    @PostMapping("/cancel/{id}")
    public JsonResult cancel(@PathVariable Long id){
        applicationService.cancel(id);
        return JsonResult.ok();
    }
    //根据applicationId和vehicleId进行修改
    @PostMapping("/distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("分配车辆，申请单编号："+applicationId+"车辆的编号："+vehicleId);
        applicationService.distribute(applicationId,vehicleId);
        return JsonResult.ok();
    }
    //根据applicationId和vehicleId进行还车操作
    @PostMapping("/back/{applicationId}/{vehicleId}")
    public JsonResult back(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("归还车辆，申请单编号："+applicationId+"车辆的编号："+vehicleId);
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}
